package com.itheima.web.controller.pms;

import com.itheima.dto.pms.ProductCreateAttributeIdDto;
import com.itheima.result.PageResult;
import com.itheima.result.ResultData;
import com.itheima.service.pms.PmsProductCategoryService;
import com.itheima.vo.pms.ProductCategoryParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("productCategory")
@Slf4j
public class PmsProductCategoryController {
    @DubboReference
    private PmsProductCategoryService pmsProductCategoryService;

    /**
     * 添加商品分类
     * @param productCreateAttributeIdDto
     * @return
     */
    @PostMapping("create")
    public ResultData create(@RequestBody ProductCreateAttributeIdDto productCreateAttributeIdDto) {
        pmsProductCategoryService.addProductCreate(productCreateAttributeIdDto);
        return ResultData.ok("操作成功" , "");
    }

    /**
     * 删除商品分类
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public ResultData deleteCategory(@PathVariable Long id) {
        return pmsProductCategoryService.deleteCategory(id);
    }

    /**
     * 查询所有一级分类及子分类
     * @return
     */
    @GetMapping("/list/withChildren")
    public ResultData listWithChildren() {
        return ResultData.ok("操作成功" , pmsProductCategoryService.listWithChildren());
    }

    /**
     * 分页查询商品分类
     * @param parentId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list/{parentId}")
    public ResultData listCategory(@PathVariable Long parentId , @RequestParam Long pageNum , @RequestParam Long pageSize) {
        return pmsProductCategoryService.listCategory(parentId , pageNum , pageSize);
    }

    /**
     * 修改导航栏显示状态
     * @param ids
     * @param navStatus
     * @return
     */
    @PostMapping("/update/navStatus")
    public ResultData updateNavStatus(@RequestParam List<Long> ids , @RequestParam Integer navStatus) {
        pmsProductCategoryService.updateNavStatus(ids , navStatus);
        return  ResultData.ok("操作成功" , "");
    }

    /**
     * 修改显示状态
     * @param ids
     * @param showStatus
     * @return
     */
    @PostMapping("/update/showStatus")
    public ResultData updateShowStatus(@RequestParam List<Long> ids , @RequestParam Integer showStatus) {
        pmsProductCategoryService.updateShowStatus(ids , showStatus);
        return  ResultData.ok("操作成功" , "");
    }

    /**
     * 根据id获取商品分类
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResultData getCategory(@PathVariable Long id) {
        return ResultData.ok("操作成功" , pmsProductCategoryService.getCategory(id));
    }

    /**
     * 修改商品分类
     * @param id
     * @param productCategoryParam
     * @return
     */
    @PostMapping("/update/{id}")
    public ResultData updateCategory(@PathVariable Long id , @RequestBody ProductCategoryParam productCategoryParam) {
        pmsProductCategoryService.updateCategory(id , productCategoryParam);
        return ResultData.ok("操作成功" , "");
    }

}
